﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace Ricciolo.StylesExplorer.Model
{
    class ObservableCollection<T> : BindingList<T>, INotifyPropertyChanged
    {

        private PropertyChangedEventHandler _propertyChanged;

        //private ListChangedEventHandler _listChanged;

        //protected virtual void OnListChanged(ListChangedEventArgs e)
        //{
        //    if (_listChanged != null)
        //        _listChanged(this, e);
        //}

        //protected override void ClearItems()
        //{
        //    base.ClearItems();

        //    OnListChanged(new ListChangedEventArgs(ListChangedType.Reset));
        //}

        //protected override void InsertItem(int index, T item)
        //{
        //    base.InsertItem(index, item);

        //    OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
        //}

        //override 

        //#region IBindingList Members

        //void IBindingList.AddIndex(PropertyDescriptor property)
        //{
        //    throw new NotImplementedException();
        //}

        //object IBindingList.AddNew()
        //{
        //    throw new NotImplementedException();
        //}

        //bool IBindingList.AllowEdit
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //bool IBindingList.AllowNew
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //bool IBindingList.AllowRemove
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)
        //{
        //    throw new NotImplementedException();
        //}

        //int IBindingList.Find(PropertyDescriptor property, object key)
        //{
        //    throw new NotImplementedException();
        //}

        //bool IBindingList.IsSorted
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //event ListChangedEventHandler IBindingList.ListChanged
        //{
        //    add { _listChanged += value; }
        //    remove { _listChanged -= value; }
        //}

        //void IBindingList.RemoveIndex(PropertyDescriptor property)
        //{
        //    throw new NotImplementedException();
        //}

        //void IBindingList.RemoveSort()
        //{
        //    throw new NotImplementedException();
        //}

        //ListSortDirection IBindingList.SortDirection
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //PropertyDescriptor IBindingList.SortProperty
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //bool IBindingList.SupportsChangeNotification
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //bool IBindingList.SupportsSearching
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //bool IBindingList.SupportsSorting
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //#endregion
        #region INotifyPropertyChanged Members

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (_propertyChanged != null)
                _propertyChanged(this, e);
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        {
            add { _propertyChanged += value; }
            remove { _propertyChanged -= value; }
        }

        #endregion
    }
}
